"use strict";
cc._RF.push(module, 'fbc9dvqZdRO6rqKofACuje5', 'Marquee');
// eazax-ccc/components/Marquee.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var Marquee = /** @class */ (function (_super) {
    __extends(Marquee, _super);
    function Marquee() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.view = null;
        _this.label = null;
        _this.texts = [];
        _this.speed = 1;
        _this.loop = false;
        _this.playOnLoad = false;
        _this.index = 0;
        _this.isPlaying = false;
        _this.endCallback = null;
        return _this;
    }
    Marquee.prototype.onLoad = function () {
        this.init();
        this.playOnLoad && this.play(0, this.loop);
    };
    Marquee.prototype.update = function (dt) {
        if (!this.isPlaying || this.texts.length === 0)
            return;
        this.updatePosition();
    };
    Marquee.prototype.init = function () {
        this.label.node.anchorX = 0;
        this.setLabel('');
    };
    Marquee.prototype.updatePosition = function () {
        this.label.node.x -= this.speed;
        if (this.label.node.x <= -(this.view.width / 2 + this.label.node.width))
            this.next();
    };
    Marquee.prototype.setLabel = function (text) {
        this.label.string = text;
        this.label.node.x = this.view.width / 2;
    };
    Marquee.prototype.next = function () {
        this.index++;
        if (this.index >= this.texts.length) {
            if (this.loop) {
                this.index = 0;
                this.setLabel(this.texts[0]);
            }
            else {
                if (this.endCallback) {
                    this.endCallback();
                    this.endCallback = null;
                }
                this.clean();
            }
        }
        else {
            this.setLabel(this.texts[this.index]);
        }
    };
    Marquee.prototype.push = function (texts) {
        var _a;
        if (Array.isArray(texts))
            (_a = this.texts).push.apply(_a, texts);
        else
            this.texts.push(texts);
    };
    Marquee.prototype.play = function (index, loop, callback) {
        if (index === void 0) { index = 0; }
        if (loop === void 0) { loop = false; }
        if (callback === void 0) { callback = null; }
        if (this.texts.length === 0)
            return;
        this.index = index < this.texts.length ? index : 0;
        this.setLabel(this.texts[this.index]);
        this.loop = loop;
        this.endCallback = callback;
        this.isPlaying = true;
    };
    Marquee.prototype.stop = function () {
        this.isPlaying = false;
        this.index = 0;
    };
    Marquee.prototype.pause = function () {
        this.isPlaying = false;
    };
    Marquee.prototype.resume = function () {
        this.isPlaying = true;
    };
    Marquee.prototype.clean = function () {
        this.stop();
        this.index = 0;
        this.texts = [];
        this.endCallback = null;
    };
    __decorate([
        property({ type: cc.Node, tooltip: CC_DEV && '容器节点' })
    ], Marquee.prototype, "view", void 0);
    __decorate([
        property({ type: cc.RichText, tooltip: CC_DEV && '文本组件' })
    ], Marquee.prototype, "label", void 0);
    __decorate([
        property({ tooltip: '文本队列' })
    ], Marquee.prototype, "texts", void 0);
    __decorate([
        property({ tooltip: CC_DEV && '每帧移动的像素' })
    ], Marquee.prototype, "speed", void 0);
    __decorate([
        property({ tooltip: CC_DEV && '循环播放' })
    ], Marquee.prototype, "loop", void 0);
    __decorate([
        property({ tooltip: CC_DEV && '自动播放' })
    ], Marquee.prototype, "playOnLoad", void 0);
    Marquee = __decorate([
        ccclass
    ], Marquee);
    return Marquee;
}(cc.Component));
exports.default = Marquee;

cc._RF.pop();